﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;

namespace MiData
{
    /// <summary>
    /// 该类应通过工具+数据库，自动生成，提高效率
    /// </summary>
    public partial class BeanDemo : MiActiveRecord
    {
        public static BeanDemo Model()
        {
            return  new BeanDemo();
        }

        private string _data;

        private string _time;


        #region Extensibility Method Declarations
        partial void OnCreated();

        partial void OnDataChanged();

        partial void OnDataChanging(string value);

        partial void OnTimeChanged();

        partial void OnTimeChanging(string value);
        #endregion

        public override string TableName
        {
            get
            {
                return "Log";
            }
        }


        [Column(Storage = "_data", Name = "Data", DbType = "TEXT(100)", AutoSync = AutoSync.Never)]
        public string Data
        {
            get
            {
                return this._data;
            }
            set
            {
                if (((_data == value)
                            == false))
                {
                    this.OnDataChanging(value);
                    this._data = value;
                    this.OnDataChanged();
                }
            }
        }

        [Column(Storage = "_time", Name = "Time", DbType = "TEXT(20)", AutoSync = AutoSync.Never)]
        [DebuggerNonUserCode()]
        public string Time
        {
            get
            {
                return this._time;
            }
            set
            {
                if (((_time == value)
                            == false))
                {
                    this.OnTimeChanging(value);
                    this._time = value;
                    this.OnTimeChanged();
                }
            }
        }


        public override string ToString()
        {
            return this.Data + ":" + this.Time;
        }


        public override IList AllData()
        {
            List<BeanDemo> o = new List<BeanDemo>();
            string sql = String.Format(BaseSelect, this.TableName);

            DbDataReader reader = this.ExecuteQuery(sql);

            while (reader.Read())
            {
                BeanDemo b = new BeanDemo();
                try
                {
                    b.Data = reader["Data"].ToString();
                    b.Time = reader["Time"].ToString();
                }
                catch (System.IndexOutOfRangeException)
                {

                }
                o.Add(b);
            }
            reader.Close();

            return o;
        }
    }
}
